<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "config/config.php";
include "auth.php";
include "DBManager.php";

// -----------------------------------------------------------------------------
// 数据库重建
// -----------------------------------------------------------------------------

/* 判断相应的文件夹是否存在 */

$path = explode("/", $dbPath);

if (!is_dir($path[0])) {
    mkdir($path[0]);
}

/* 如果数据库不存在，创建数据库 */

if (!is_file($dbPath)) {

    $db = new DBManager("sqlite:" . $dbPath);
    $db->createTables();

    $str = "Refresh:3,Url=" . $homepage;
    header($str);

    echo <<<BBB
        数据库创建成功！
        <br />
        3秒后自动跳转到主页！
    BBB;

    exit();

}

$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$numberOfCategories = $db->getNumberOfCategories();
$totalNumberOfLinks = $db->getTotalNumberOfLinks();
$totalTimesOfClick =  $db->getTotalTimesOfClick();

// -----------------------------------------------------------------------------
?>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title><?php echo $siteTitle; ?></title>
    <link rel="stylesheet" href="resources/bootstrap-5.2.0-beta1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="global.css">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<script src="resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="resources/jQuery/jquery-3.5.1.js"></script>
<?php include "globalNavbar.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<!--div:container start-->
<div class="mainContainer container container-fluid mb-5">

    <!-- 导航栏 开始 -->
    <div class="mt-3">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a class="text-decoration-none" href="<?php echo $homepage; ?>">首页</a></li>
            </ol>
        </nav>
    </div>
    <!-- 导航栏 结束 -->

    <div class="list-group mt-3">
        <a href="nav.php" class="list-group-item list-group-item-action">网址导航</a>
        <a href="category/index.php" class="list-group-item list-group-item-action d-flex align-items-center">
            <span class="w-100">分类管理</span>
            <span class="flex-shrink-0">
                <span class="badge rounded-pill text-bg-light"><?php echo $numberOfCategories; ?>分类</span>
                <span class="badge rounded-pill text-bg-light"><?php echo $totalNumberOfLinks; ?>网址</span>
                <span class="badge rounded-pill text-bg-light"><?php echo $totalTimesOfClick; ?>点击</span>
            </span>
        </a>
        <a href="recent/index.php" class="list-group-item list-group-item-action">最近</a>
        <a href="search/index.php" class="list-group-item list-group-item-action">搜索</a>
    </div>

    <!--<div class="list-group mt-3">-->
    <!--    <a href="" class="list-group-item list-group-item-action">最常访问</a>-->
    <!--    <a href="" class="list-group-item list-group-item-action">最近访问</a>-->
    <!--</div>-->

    <div class="list-group mt-3">
        <a href="options/index.php" class="list-group-item list-group-item-action">偏好设置</a>
        <a href="recreateDatabase/index.php" class="list-group-item list-group-item-action">重置数据库</a>
        <a href="about/index.php" class="list-group-item list-group-item-action">关于</a>
    </div>

</div>
<!--div:container end-->

<!-- ----------------------------------------------------------------------- -->

</body>
</html>
